<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.SysTools.FileCleanup</span><span>
</span><span id="line-3"></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TempFileLifetime"><span class="hs-identifier">TempFileLifetime</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-4"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#cleanTempDirs"><span class="hs-identifier">cleanTempDirs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#cleanTempFiles"><span class="hs-identifier">cleanTempFiles</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#cleanCurrentModuleTempFiles"><span class="hs-identifier">cleanCurrentModuleTempFiles</span></a></span><span>
</span><span id="line-5"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#addFilesToClean"><span class="hs-identifier">addFilesToClean</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#changeTempFilesLifetime"><span class="hs-identifier">changeTempFilesLifetime</span></a></span><span>
</span><span id="line-6"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#newTempName"><span class="hs-identifier">newTempName</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#newTempLibName"><span class="hs-identifier">newTempLibName</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#newTempDir"><span class="hs-identifier">newTempDir</span></a></span><span>
</span><span id="line-7"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#withSystemTempDirectory"><span class="hs-identifier">withSystemTempDirectory</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#withTempDirectory"><span class="hs-identifier">withTempDirectory</span></a></span><span>
</span><span id="line-8"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-13"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html"><span class="hs-identifier">GHC.Utils.Error</span></a></span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Exception.html"><span class="hs-identifier">GHC.Utils.Exception</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Exception</span></span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Phases.html"><span class="hs-identifier">GHC.Driver.Phases</span></a></span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../containers/src/Data.Set.html#"><span class="hs-identifier">Data.Set</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Set</span></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.html#"><span class="hs-identifier">Data.Map</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Map</span></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.IORef.html#"><span class="hs-identifier">Data.IORef</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../directory/src/System.Directory.html#"><span class="hs-identifier">System.Directory</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../filepath/src/System.FilePath.html#"><span class="hs-identifier">System.FilePath</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/System.IO.Error.html#"><span class="hs-identifier">System.IO.Error</span></a></span><span class="hs-cpp">

#if !defined(mingw32_HOST_OS)
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">System.Posix.Internals</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- | Used when a temp file is created. This determines which component Set of</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- FilesToClean will get the temp file</span><span>
</span><span id="line-34"></span><span class="hs-keyword">data</span><span> </span><span id="TempFileLifetime"><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TempFileLifetime"><span class="hs-identifier hs-var">TempFileLifetime</span></a></span></span><span>
</span><span id="line-35"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="TFL_CurrentModule"><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TFL_CurrentModule"><span class="hs-identifier hs-var">TFL_CurrentModule</span></a></span></span><span>
</span><span id="line-36"></span><span>  </span><span class="hs-comment">-- ^ A file with lifetime TFL_CurrentModule will be cleaned up at the</span><span>
</span><span id="line-37"></span><span>  </span><span class="hs-comment">-- end of upweep_mod</span><span>
</span><span id="line-38"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="TFL_GhcSession"><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TFL_GhcSession"><span class="hs-identifier hs-var">TFL_GhcSession</span></a></span></span><span>
</span><span id="line-39"></span><span>  </span><span class="hs-comment">-- ^ A file with lifetime TFL_GhcSession will be cleaned up at the end of</span><span>
</span><span id="line-40"></span><span>  </span><span class="hs-comment">-- runGhc(T)</span><span>
</span><span id="line-41"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680933228"><span id="local-6989586621680933230"><span id="local-6989586621680933232"><span class="annot"><span class="annottext">Int -&gt; TempFileLifetime -&gt; ShowS
[TempFileLifetime] -&gt; ShowS
TempFileLifetime -&gt; String
(Int -&gt; TempFileLifetime -&gt; ShowS)
-&gt; (TempFileLifetime -&gt; String)
-&gt; ([TempFileLifetime] -&gt; ShowS)
-&gt; Show TempFileLifetime
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [TempFileLifetime] -&gt; ShowS
$cshowList :: [TempFileLifetime] -&gt; ShowS
show :: TempFileLifetime -&gt; String
$cshow :: TempFileLifetime -&gt; String
showsPrec :: Int -&gt; TempFileLifetime -&gt; ShowS
$cshowsPrec :: Int -&gt; TempFileLifetime -&gt; ShowS
</span><a href="../../base/src/GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#cleanTempDirs"><span class="hs-identifier hs-type">cleanTempDirs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span id="cleanTempDirs"><span class="annot"><span class="annottext">cleanTempDirs :: DynFlags -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#cleanTempDirs"><span class="hs-identifier hs-var hs-var">cleanTempDirs</span></a></span></span><span> </span><span id="local-6989586621680933226"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933226"><span class="hs-identifier hs-var">dflags</span></a></span></span><span>
</span><span id="line-45"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_KeepTmpFiles"><span class="hs-identifier hs-var">Opt_KeepTmpFiles</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933226"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span>   </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ()
forall a. IO a -&gt; IO a
</span><a href="../../base/src/GHC.IO.html#mask_"><span class="hs-identifier hs-var">mask_</span></a></span><span>
</span><span id="line-47"></span><span>   </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933221"><span class="annot"><span class="annottext">ref :: IORef (Map String String)
</span><a href="#local-6989586621680933221"><span class="hs-identifier hs-var hs-var">ref</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IORef (Map String String)
</span><a href="GHC.Driver.Session.html#dirsToClean"><span class="hs-identifier hs-var hs-var">dirsToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933226"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-48"></span><span>        </span><span id="local-6989586621680933219"><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933219"><span class="hs-identifier hs-var">ds</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Map String String)
-&gt; (Map String String -&gt; (Map String String, Map String String))
-&gt; IO (Map String String)
forall a b. IORef a -&gt; (a -&gt; (a, b)) -&gt; IO b
</span><a href="../../base/src/GHC.IORef.html#atomicModifyIORef%27"><span class="hs-identifier hs-var">atomicModifyIORef'</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Map String String)
</span><a href="#local-6989586621680933221"><span class="hs-identifier hs-var">ref</span></a></span><span> </span><span class="annot"><span class="annottext">((Map String String -&gt; (Map String String, Map String String))
 -&gt; IO (Map String String))
-&gt; (Map String String -&gt; (Map String String, Map String String))
-&gt; IO (Map String String)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680933217"><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933217"><span class="hs-identifier hs-var">ds</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map String String
forall k a. Map k a
</span><a href="../../containers/src/Data.Map.Internal.html#empty"><span class="hs-identifier hs-var">Map.empty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933217"><span class="hs-identifier hs-var">ds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span>        </span><span class="annot"><span class="annottext">DynFlags -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeTmpDirs"><span class="hs-identifier hs-var">removeTmpDirs</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933226"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map String String -&gt; [String]
forall k a. Map k a -&gt; [a]
</span><a href="../../containers/src/Data.Map.Internal.html#elems"><span class="hs-identifier hs-var">Map.elems</span></a></span><span> </span><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933219"><span class="hs-identifier hs-var">ds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span class="hs-comment">-- | Delete all files in @filesToClean dflags@.</span><span>
</span><span id="line-52"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#cleanTempFiles"><span class="hs-identifier hs-type">cleanTempFiles</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span id="cleanTempFiles"><span class="annot"><span class="annottext">cleanTempFiles :: DynFlags -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#cleanTempFiles"><span class="hs-identifier hs-var hs-var">cleanTempFiles</span></a></span></span><span> </span><span id="local-6989586621680933213"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933213"><span class="hs-identifier hs-var">dflags</span></a></span></span><span>
</span><span id="line-54"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_KeepTmpFiles"><span class="hs-identifier hs-var">Opt_KeepTmpFiles</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933213"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span>   </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ()
forall a. IO a -&gt; IO a
</span><a href="../../base/src/GHC.IO.html#mask_"><span class="hs-identifier hs-var">mask_</span></a></span><span>
</span><span id="line-56"></span><span>   </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933212"><span class="annot"><span class="annottext">ref :: IORef FilesToClean
</span><a href="#local-6989586621680933212"><span class="hs-identifier hs-var hs-var">ref</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IORef FilesToClean
</span><a href="GHC.Driver.Session.html#filesToClean"><span class="hs-identifier hs-var hs-var">filesToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933213"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-57"></span><span>        </span><span id="local-6989586621680933210"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933210"><span class="hs-identifier hs-var">to_delete</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef FilesToClean
-&gt; (FilesToClean -&gt; (FilesToClean, [String])) -&gt; IO [String]
forall a b. IORef a -&gt; (a -&gt; (a, b)) -&gt; IO b
</span><a href="../../base/src/GHC.IORef.html#atomicModifyIORef%27"><span class="hs-identifier hs-var">atomicModifyIORef'</span></a></span><span> </span><span class="annot"><span class="annottext">IORef FilesToClean
</span><a href="#local-6989586621680933212"><span class="hs-identifier hs-var">ref</span></a></span><span> </span><span class="annot"><span class="annottext">((FilesToClean -&gt; (FilesToClean, [String])) -&gt; IO [String])
-&gt; (FilesToClean -&gt; (FilesToClean, [String])) -&gt; IO [String]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-58"></span><span>            </span><span class="hs-glyph">\</span><span class="annot"><a href="GHC.Driver.Session.html#FilesToClean"><span class="hs-identifier hs-type">FilesToClean</span></a></span><span>
</span><span id="line-59"></span><span>                </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ftcCurrentModule :: FilesToClean -&gt; Set String
</span><a href="GHC.Driver.Session.html#ftcCurrentModule"><span class="hs-identifier hs-var">ftcCurrentModule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680933207"><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933207"><span class="hs-identifier hs-var">cm_files</span></a></span></span><span>
</span><span id="line-60"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ftcGhcSession :: FilesToClean -&gt; Set String
</span><a href="GHC.Driver.Session.html#ftcGhcSession"><span class="hs-identifier hs-var">ftcGhcSession</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680933205"><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933205"><span class="hs-identifier hs-var">gs_files</span></a></span></span><span>
</span><span id="line-61"></span><span>                </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">FilesToClean
</span><a href="GHC.Driver.Session.html#emptyFilesToClean"><span class="hs-identifier hs-var">emptyFilesToClean</span></a></span><span>
</span><span id="line-62"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Set String -&gt; [String]
forall a. Set a -&gt; [a]
</span><a href="../../containers/src/Data.Set.Internal.html#toList"><span class="hs-identifier hs-var">Set.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933207"><span class="hs-identifier hs-var">cm_files</span></a></span><span> </span><span class="annot"><span class="annottext">[String] -&gt; [String] -&gt; [String]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Set String -&gt; [String]
forall a. Set a -&gt; [a]
</span><a href="../../containers/src/Data.Set.Internal.html#toList"><span class="hs-identifier hs-var">Set.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933205"><span class="hs-identifier hs-var">gs_files</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-63"></span><span>        </span><span class="annot"><span class="annottext">DynFlags -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeTmpFiles"><span class="hs-identifier hs-var">removeTmpFiles</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933213"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933210"><span class="hs-identifier hs-var">to_delete</span></a></span><span>
</span><span id="line-64"></span><span>
</span><span id="line-65"></span><span class="hs-comment">-- | Delete all files in @filesToClean dflags@. That have lifetime</span><span>
</span><span id="line-66"></span><span class="hs-comment">-- TFL_CurrentModule.</span><span>
</span><span id="line-67"></span><span class="hs-comment">-- If a file must be cleaned eventually, but must survive a</span><span>
</span><span id="line-68"></span><span class="hs-comment">-- cleanCurrentModuleTempFiles, ensure it has lifetime TFL_GhcSession.</span><span>
</span><span id="line-69"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#cleanCurrentModuleTempFiles"><span class="hs-identifier hs-type">cleanCurrentModuleTempFiles</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-70"></span><span id="cleanCurrentModuleTempFiles"><span class="annot"><span class="annottext">cleanCurrentModuleTempFiles :: DynFlags -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#cleanCurrentModuleTempFiles"><span class="hs-identifier hs-var hs-var">cleanCurrentModuleTempFiles</span></a></span></span><span> </span><span id="local-6989586621680933201"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933201"><span class="hs-identifier hs-var">dflags</span></a></span></span><span>
</span><span id="line-71"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_KeepTmpFiles"><span class="hs-identifier hs-var">Opt_KeepTmpFiles</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933201"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span>   </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ()
forall a. IO a -&gt; IO a
</span><a href="../../base/src/GHC.IO.html#mask_"><span class="hs-identifier hs-var">mask_</span></a></span><span>
</span><span id="line-73"></span><span>   </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933200"><span class="annot"><span class="annottext">ref :: IORef FilesToClean
</span><a href="#local-6989586621680933200"><span class="hs-identifier hs-var hs-var">ref</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IORef FilesToClean
</span><a href="GHC.Driver.Session.html#filesToClean"><span class="hs-identifier hs-var hs-var">filesToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933201"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-74"></span><span>        </span><span id="local-6989586621680933199"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933199"><span class="hs-identifier hs-var">to_delete</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef FilesToClean
-&gt; (FilesToClean -&gt; (FilesToClean, [String])) -&gt; IO [String]
forall a b. IORef a -&gt; (a -&gt; (a, b)) -&gt; IO b
</span><a href="../../base/src/GHC.IORef.html#atomicModifyIORef%27"><span class="hs-identifier hs-var">atomicModifyIORef'</span></a></span><span> </span><span class="annot"><span class="annottext">IORef FilesToClean
</span><a href="#local-6989586621680933200"><span class="hs-identifier hs-var">ref</span></a></span><span> </span><span class="annot"><span class="annottext">((FilesToClean -&gt; (FilesToClean, [String])) -&gt; IO [String])
-&gt; (FilesToClean -&gt; (FilesToClean, [String])) -&gt; IO [String]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-75"></span><span>            </span><span class="hs-glyph">\</span><span id="local-6989586621680933198"><span class="annot"><span class="annottext">ftc :: FilesToClean
</span><a href="#local-6989586621680933198"><span class="hs-identifier hs-var">ftc</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.Driver.Session.html#FilesToClean"><span class="hs-identifier hs-type">FilesToClean</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">ftcCurrentModule :: FilesToClean -&gt; Set String
</span><a href="GHC.Driver.Session.html#ftcCurrentModule"><span class="hs-identifier hs-var">ftcCurrentModule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680933197"><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933197"><span class="hs-identifier hs-var">cm_files</span></a></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-76"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilesToClean
</span><a href="#local-6989586621680933198"><span class="hs-identifier hs-var">ftc</span></a></span><span> </span><span class="hs-special">{</span><span class="annot"><span class="annottext">ftcCurrentModule :: Set String
</span><a href="GHC.Driver.Session.html#ftcCurrentModule"><span class="hs-identifier hs-var">ftcCurrentModule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Set String
forall a. Set a
</span><a href="../../containers/src/Data.Set.Internal.html#empty"><span class="hs-identifier hs-var">Set.empty</span></a></span><span class="hs-special">}</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Set String -&gt; [String]
forall a. Set a -&gt; [a]
</span><a href="../../containers/src/Data.Set.Internal.html#toList"><span class="hs-identifier hs-var">Set.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933197"><span class="hs-identifier hs-var">cm_files</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-77"></span><span>        </span><span class="annot"><span class="annottext">DynFlags -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeTmpFiles"><span class="hs-identifier hs-var">removeTmpFiles</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933201"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933199"><span class="hs-identifier hs-var">to_delete</span></a></span><span>
</span><span id="line-78"></span><span>
</span><span id="line-79"></span><span class="hs-comment">-- | Ensure that new_files are cleaned on the next call of</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- 'cleanTempFiles' or 'cleanCurrentModuleTempFiles', depending on lifetime.</span><span>
</span><span id="line-81"></span><span class="hs-comment">-- If any of new_files are already tracked, they will have their lifetime</span><span>
</span><span id="line-82"></span><span class="hs-comment">-- updated.</span><span>
</span><span id="line-83"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#addFilesToClean"><span class="hs-identifier hs-type">addFilesToClean</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TempFileLifetime"><span class="hs-identifier hs-type">TempFileLifetime</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-84"></span><span id="addFilesToClean"><span class="annot"><span class="annottext">addFilesToClean :: DynFlags -&gt; TempFileLifetime -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#addFilesToClean"><span class="hs-identifier hs-var hs-var">addFilesToClean</span></a></span></span><span> </span><span id="local-6989586621680933194"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933194"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680933193"><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933193"><span class="hs-identifier hs-var">lifetime</span></a></span></span><span> </span><span id="local-6989586621680933192"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933192"><span class="hs-identifier hs-var">new_files</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef FilesToClean -&gt; (FilesToClean -&gt; FilesToClean) -&gt; IO ()
forall a. IORef a -&gt; (a -&gt; a) -&gt; IO ()
</span><a href="../../base/src/Data.IORef.html#modifyIORef%27"><span class="hs-identifier hs-var">modifyIORef'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; IORef FilesToClean
</span><a href="GHC.Driver.Session.html#filesToClean"><span class="hs-identifier hs-var hs-var">filesToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933194"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((FilesToClean -&gt; FilesToClean) -&gt; IO ())
-&gt; (FilesToClean -&gt; FilesToClean) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-85"></span><span>  </span><span class="hs-glyph">\</span><span class="annot"><a href="GHC.Driver.Session.html#FilesToClean"><span class="hs-identifier hs-type">FilesToClean</span></a></span><span>
</span><span id="line-86"></span><span>    </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ftcCurrentModule :: FilesToClean -&gt; Set String
</span><a href="GHC.Driver.Session.html#ftcCurrentModule"><span class="hs-identifier hs-var">ftcCurrentModule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680933190"><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933190"><span class="hs-identifier hs-var">cm_files</span></a></span></span><span>
</span><span id="line-87"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ftcGhcSession :: FilesToClean -&gt; Set String
</span><a href="GHC.Driver.Session.html#ftcGhcSession"><span class="hs-identifier hs-var">ftcGhcSession</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680933189"><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933189"><span class="hs-identifier hs-var">gs_files</span></a></span></span><span>
</span><span id="line-88"></span><span>    </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933193"><span class="hs-identifier hs-var">lifetime</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-89"></span><span>      </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="GHC.SysTools.FileCleanup.html#TFL_CurrentModule"><span class="hs-identifier hs-var">TFL_CurrentModule</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FilesToClean :: Set String -&gt; Set String -&gt; FilesToClean
</span><a href="GHC.Driver.Session.html#FilesToClean"><span class="hs-identifier hs-type">FilesToClean</span></a></span><span>
</span><span id="line-90"></span><span>        </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ftcCurrentModule :: Set String
</span><a href="GHC.Driver.Session.html#ftcCurrentModule"><span class="hs-identifier hs-var">ftcCurrentModule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933190"><span class="hs-identifier hs-var">cm_files</span></a></span><span> </span><span class="annot"><span class="annottext">Set String -&gt; Set String -&gt; Set String
forall a. Ord a =&gt; Set a -&gt; Set a -&gt; Set a
</span><a href="../../containers/src/Data.Set.Internal.html#union"><span class="hs-operator hs-var">`Set.union`</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933187"><span class="hs-identifier hs-var">new_files_set</span></a></span><span>
</span><span id="line-91"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ftcGhcSession :: Set String
</span><a href="GHC.Driver.Session.html#ftcGhcSession"><span class="hs-identifier hs-var">ftcGhcSession</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933189"><span class="hs-identifier hs-var">gs_files</span></a></span><span> </span><span class="annot"><span class="annottext">Set String -&gt; Set String -&gt; Set String
forall a. Ord a =&gt; Set a -&gt; Set a -&gt; Set a
</span><a href="../../containers/src/Data.Set.Internal.html#difference"><span class="hs-operator hs-var">`Set.difference`</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933187"><span class="hs-identifier hs-var">new_files_set</span></a></span><span>
</span><span id="line-92"></span><span>        </span><span class="hs-special">}</span><span>
</span><span id="line-93"></span><span>      </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="GHC.SysTools.FileCleanup.html#TFL_GhcSession"><span class="hs-identifier hs-var">TFL_GhcSession</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FilesToClean :: Set String -&gt; Set String -&gt; FilesToClean
</span><a href="GHC.Driver.Session.html#FilesToClean"><span class="hs-identifier hs-type">FilesToClean</span></a></span><span>
</span><span id="line-94"></span><span>        </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ftcCurrentModule :: Set String
</span><a href="GHC.Driver.Session.html#ftcCurrentModule"><span class="hs-identifier hs-var">ftcCurrentModule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933190"><span class="hs-identifier hs-var">cm_files</span></a></span><span> </span><span class="annot"><span class="annottext">Set String -&gt; Set String -&gt; Set String
forall a. Ord a =&gt; Set a -&gt; Set a -&gt; Set a
</span><a href="../../containers/src/Data.Set.Internal.html#difference"><span class="hs-operator hs-var">`Set.difference`</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933187"><span class="hs-identifier hs-var">new_files_set</span></a></span><span>
</span><span id="line-95"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ftcGhcSession :: Set String
</span><a href="GHC.Driver.Session.html#ftcGhcSession"><span class="hs-identifier hs-var">ftcGhcSession</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933189"><span class="hs-identifier hs-var">gs_files</span></a></span><span> </span><span class="annot"><span class="annottext">Set String -&gt; Set String -&gt; Set String
forall a. Ord a =&gt; Set a -&gt; Set a -&gt; Set a
</span><a href="../../containers/src/Data.Set.Internal.html#union"><span class="hs-operator hs-var">`Set.union`</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933187"><span class="hs-identifier hs-var">new_files_set</span></a></span><span>
</span><span id="line-96"></span><span>        </span><span class="hs-special">}</span><span>
</span><span id="line-97"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-98"></span><span>    </span><span id="local-6989586621680933187"><span class="annot"><span class="annottext">new_files_set :: Set String
</span><a href="#local-6989586621680933187"><span class="hs-identifier hs-var hs-var">new_files_set</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[String] -&gt; Set String
forall a. Ord a =&gt; [a] -&gt; Set a
</span><a href="../../containers/src/Data.Set.Internal.html#fromList"><span class="hs-identifier hs-var">Set.fromList</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933192"><span class="hs-identifier hs-var">new_files</span></a></span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span class="hs-comment">-- | Update the lifetime of files already being tracked. If any files are</span><span>
</span><span id="line-101"></span><span class="hs-comment">-- not being tracked they will be discarded.</span><span>
</span><span id="line-102"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#changeTempFilesLifetime"><span class="hs-identifier hs-type">changeTempFilesLifetime</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TempFileLifetime"><span class="hs-identifier hs-type">TempFileLifetime</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-103"></span><span id="changeTempFilesLifetime"><span class="annot"><span class="annottext">changeTempFilesLifetime :: DynFlags -&gt; TempFileLifetime -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#changeTempFilesLifetime"><span class="hs-identifier hs-var hs-var">changeTempFilesLifetime</span></a></span></span><span> </span><span id="local-6989586621680933182"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933182"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680933181"><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933181"><span class="hs-identifier hs-var">lifetime</span></a></span></span><span> </span><span id="local-6989586621680933180"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933180"><span class="hs-identifier hs-var">files</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-104"></span><span>  </span><span class="annot"><a href="GHC.Driver.Session.html#FilesToClean"><span class="hs-identifier hs-type">FilesToClean</span></a></span><span>
</span><span id="line-105"></span><span>    </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ftcCurrentModule :: FilesToClean -&gt; Set String
</span><a href="GHC.Driver.Session.html#ftcCurrentModule"><span class="hs-identifier hs-var">ftcCurrentModule</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680933179"><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933179"><span class="hs-identifier hs-var">cm_files</span></a></span></span><span>
</span><span id="line-106"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ftcGhcSession :: FilesToClean -&gt; Set String
</span><a href="GHC.Driver.Session.html#ftcGhcSession"><span class="hs-identifier hs-var">ftcGhcSession</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680933178"><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933178"><span class="hs-identifier hs-var">gs_files</span></a></span></span><span>
</span><span id="line-107"></span><span>    </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef FilesToClean -&gt; IO FilesToClean
forall a. IORef a -&gt; IO a
</span><a href="../../base/src/GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; IORef FilesToClean
</span><a href="GHC.Driver.Session.html#filesToClean"><span class="hs-identifier hs-var hs-var">filesToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933182"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-108"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933176"><span class="annot"><span class="annottext">old_set :: Set String
</span><a href="#local-6989586621680933176"><span class="hs-identifier hs-var hs-var">old_set</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933181"><span class="hs-identifier hs-var">lifetime</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-109"></span><span>        </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="GHC.SysTools.FileCleanup.html#TFL_CurrentModule"><span class="hs-identifier hs-var">TFL_CurrentModule</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933178"><span class="hs-identifier hs-var">gs_files</span></a></span><span>
</span><span id="line-110"></span><span>        </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="GHC.SysTools.FileCleanup.html#TFL_GhcSession"><span class="hs-identifier hs-var">TFL_GhcSession</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933179"><span class="hs-identifier hs-var">cm_files</span></a></span><span>
</span><span id="line-111"></span><span>      </span><span id="local-6989586621680933173"><span class="annot"><span class="annottext">existing_files :: [String]
</span><a href="#local-6989586621680933173"><span class="hs-identifier hs-var hs-var">existing_files</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933172"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680933172"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933172"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933180"><span class="hs-identifier hs-var">files</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933172"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Set String -&gt; Bool
forall a. Ord a =&gt; a -&gt; Set a -&gt; Bool
</span><a href="../../containers/src/Data.Set.Internal.html#member"><span class="hs-operator hs-var">`Set.member`</span></a></span><span> </span><span class="annot"><span class="annottext">Set String
</span><a href="#local-6989586621680933176"><span class="hs-identifier hs-var">old_set</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-112"></span><span>  </span><span class="annot"><span class="annottext">DynFlags -&gt; TempFileLifetime -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#addFilesToClean"><span class="hs-identifier hs-var">addFilesToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933182"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933181"><span class="hs-identifier hs-var">lifetime</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933173"><span class="hs-identifier hs-var">existing_files</span></a></span><span>
</span><span id="line-113"></span><span>
</span><span id="line-114"></span><span class="hs-comment">-- Return a unique numeric temp file suffix</span><span>
</span><span id="line-115"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#newTempSuffix"><span class="hs-identifier hs-type">newTempSuffix</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-116"></span><span id="newTempSuffix"><span class="annot"><span class="annottext">newTempSuffix :: DynFlags -&gt; IO Int
</span><a href="GHC.SysTools.FileCleanup.html#newTempSuffix"><span class="hs-identifier hs-var hs-var">newTempSuffix</span></a></span></span><span> </span><span id="local-6989586621680933169"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933169"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-117"></span><span>  </span><span class="annot"><span class="annottext">IORef Int -&gt; (Int -&gt; (Int, Int)) -&gt; IO Int
forall a b. IORef a -&gt; (a -&gt; (a, b)) -&gt; IO b
</span><a href="../../base/src/GHC.IORef.html#atomicModifyIORef%27"><span class="hs-identifier hs-var">atomicModifyIORef'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; IORef Int
</span><a href="GHC.Driver.Session.html#nextTempSuffix"><span class="hs-identifier hs-var hs-var">nextTempSuffix</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933169"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((Int -&gt; (Int, Int)) -&gt; IO Int) -&gt; (Int -&gt; (Int, Int)) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680933167"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933167"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933167"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933167"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-comment">-- Find a temporary name that doesn't already exist.</span><span>
</span><span id="line-120"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#newTempName"><span class="hs-identifier hs-type">newTempName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TempFileLifetime"><span class="hs-identifier hs-type">TempFileLifetime</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html#Suffix"><span class="hs-identifier hs-type">Suffix</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-121"></span><span id="newTempName"><span class="annot"><span class="annottext">newTempName :: DynFlags -&gt; TempFileLifetime -&gt; String -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#newTempName"><span class="hs-identifier hs-var hs-var">newTempName</span></a></span></span><span> </span><span id="local-6989586621680933164"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933164"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680933163"><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933163"><span class="hs-identifier hs-var">lifetime</span></a></span></span><span> </span><span id="local-6989586621680933162"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933162"><span class="hs-identifier hs-var">extn</span></a></span></span><span>
</span><span id="line-122"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621680933161"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933161"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#getTempDir"><span class="hs-identifier hs-var">getTempDir</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933164"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-123"></span><span>       </span><span class="annot"><span class="annottext">String -&gt; IO String
</span><a href="#local-6989586621680933159"><span class="hs-identifier hs-var">findTempName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933161"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="../../filepath/src/System.FilePath.Windows.html#%3C%2F%3E"><span class="hs-operator hs-var">&lt;/&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ghc_&quot;</span></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- See Note [Deterministic base name]</span><span>
</span><span id="line-124"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-125"></span><span>    </span><span class="annot"><a href="#local-6989586621680933159"><span class="hs-identifier hs-type">findTempName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-126"></span><span>    </span><span id="local-6989586621680933159"><span class="annot"><span class="annottext">findTempName :: String -&gt; IO String
</span><a href="#local-6989586621680933159"><span class="hs-identifier hs-var hs-var">findTempName</span></a></span></span><span> </span><span id="local-6989586621680933157"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933157"><span class="hs-identifier hs-var">prefix</span></a></span></span><span>
</span><span id="line-127"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621680933156"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933156"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IO Int
</span><a href="GHC.SysTools.FileCleanup.html#newTempSuffix"><span class="hs-identifier hs-var">newTempSuffix</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933164"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-128"></span><span>           </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933154"><span class="annot"><span class="annottext">filename :: String
</span><a href="#local-6989586621680933154"><span class="hs-identifier hs-var hs-var">filename</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933157"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933156"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="../../filepath/src/System.FilePath.Windows.html#%3C.%3E"><span class="hs-operator hs-var">&lt;.&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933162"><span class="hs-identifier hs-var">extn</span></a></span><span>
</span><span id="line-129"></span><span>           </span><span id="local-6989586621680933151"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680933151"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO Bool
</span><a href="../../directory/src/System.Directory.html#doesFileExist"><span class="hs-identifier hs-var">doesFileExist</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933154"><span class="hs-identifier hs-var">filename</span></a></span><span>
</span><span id="line-130"></span><span>           </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680933151"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
</span><a href="#local-6989586621680933159"><span class="hs-identifier hs-var">findTempName</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933157"><span class="hs-identifier hs-var">prefix</span></a></span><span>
</span><span id="line-131"></span><span>                </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-comment">-- clean it up later</span><span>
</span><span id="line-132"></span><span>                        </span><span class="annot"><span class="annottext">DynFlags -&gt; TempFileLifetime -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#addFilesToClean"><span class="hs-identifier hs-var">addFilesToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933164"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933163"><span class="hs-identifier hs-var">lifetime</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933154"><span class="hs-identifier hs-var">filename</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-133"></span><span>                        </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933154"><span class="hs-identifier hs-var">filename</span></a></span><span>
</span><span id="line-134"></span><span>
</span><span id="line-135"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#newTempDir"><span class="hs-identifier hs-type">newTempDir</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-136"></span><span id="newTempDir"><span class="annot"><span class="annottext">newTempDir :: DynFlags -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#newTempDir"><span class="hs-identifier hs-var hs-var">newTempDir</span></a></span></span><span> </span><span id="local-6989586621680933149"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933149"><span class="hs-identifier hs-var">dflags</span></a></span></span><span>
</span><span id="line-137"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621680933148"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933148"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#getTempDir"><span class="hs-identifier hs-var">getTempDir</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933149"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-138"></span><span>       </span><span class="annot"><span class="annottext">String -&gt; IO String
</span><a href="#local-6989586621680933147"><span class="hs-identifier hs-var">findTempDir</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933148"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="../../filepath/src/System.FilePath.Windows.html#%3C%2F%3E"><span class="hs-operator hs-var">&lt;/&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ghc_&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-139"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-140"></span><span>    </span><span class="annot"><a href="#local-6989586621680933147"><span class="hs-identifier hs-type">findTempDir</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-141"></span><span>    </span><span id="local-6989586621680933147"><span class="annot"><span class="annottext">findTempDir :: String -&gt; IO String
</span><a href="#local-6989586621680933147"><span class="hs-identifier hs-var hs-var">findTempDir</span></a></span></span><span> </span><span id="local-6989586621680933146"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933146"><span class="hs-identifier hs-var">prefix</span></a></span></span><span>
</span><span id="line-142"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621680933145"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933145"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IO Int
</span><a href="GHC.SysTools.FileCleanup.html#newTempSuffix"><span class="hs-identifier hs-var">newTempSuffix</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933149"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-143"></span><span>           </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933143"><span class="annot"><span class="annottext">filename :: String
</span><a href="#local-6989586621680933143"><span class="hs-identifier hs-var hs-var">filename</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933146"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933145"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-144"></span><span>           </span><span id="local-6989586621680933142"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680933142"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO Bool
</span><a href="../../directory/src/System.Directory.html#doesDirectoryExist"><span class="hs-identifier hs-var">doesDirectoryExist</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933143"><span class="hs-identifier hs-var">filename</span></a></span><span>
</span><span id="line-145"></span><span>           </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680933142"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
</span><a href="#local-6989586621680933147"><span class="hs-identifier hs-var">findTempDir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933146"><span class="hs-identifier hs-var">prefix</span></a></span><span>
</span><span id="line-146"></span><span>                </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="../../directory/src/System.Directory.html#createDirectory"><span class="hs-identifier hs-var">createDirectory</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933143"><span class="hs-identifier hs-var">filename</span></a></span><span>
</span><span id="line-147"></span><span>                        </span><span class="hs-comment">-- see mkTempDir below; this is wrong: -&gt; consIORef (dirsToClean dflags) filename</span><span>
</span><span id="line-148"></span><span>                        </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933143"><span class="hs-identifier hs-var">filename</span></a></span><span>
</span><span id="line-149"></span><span>
</span><span id="line-150"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#newTempLibName"><span class="hs-identifier hs-type">newTempLibName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#TempFileLifetime"><span class="hs-identifier hs-type">TempFileLifetime</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html#Suffix"><span class="hs-identifier hs-type">Suffix</span></a></span><span>
</span><span id="line-151"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-152"></span><span id="newTempLibName"><span class="annot"><span class="annottext">newTempLibName :: DynFlags
-&gt; TempFileLifetime -&gt; String -&gt; IO (String, String, String)
</span><a href="GHC.SysTools.FileCleanup.html#newTempLibName"><span class="hs-identifier hs-var hs-var">newTempLibName</span></a></span></span><span> </span><span id="local-6989586621680933139"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933139"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680933138"><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933138"><span class="hs-identifier hs-var">lifetime</span></a></span></span><span> </span><span id="local-6989586621680933137"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933137"><span class="hs-identifier hs-var">extn</span></a></span></span><span>
</span><span id="line-153"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621680933136"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933136"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#getTempDir"><span class="hs-identifier hs-var">getTempDir</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933139"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-154"></span><span>       </span><span class="annot"><span class="annottext">String -&gt; String -&gt; IO (String, String, String)
</span><a href="#local-6989586621680933135"><span class="hs-identifier hs-var">findTempName</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933136"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ghc_&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-155"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-156"></span><span>    </span><span class="annot"><a href="#local-6989586621680933135"><span class="hs-identifier hs-type">findTempName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-157"></span><span>    </span><span id="local-6989586621680933135"><span class="annot"><span class="annottext">findTempName :: String -&gt; String -&gt; IO (String, String, String)
</span><a href="#local-6989586621680933135"><span class="hs-identifier hs-var hs-var">findTempName</span></a></span></span><span> </span><span id="local-6989586621680933134"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933134"><span class="hs-identifier hs-var">dir</span></a></span></span><span> </span><span id="local-6989586621680933133"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933133"><span class="hs-identifier hs-var">prefix</span></a></span></span><span>
</span><span id="line-158"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621680933132"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933132"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IO Int
</span><a href="GHC.SysTools.FileCleanup.html#newTempSuffix"><span class="hs-identifier hs-var">newTempSuffix</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933139"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-comment">-- See Note [Deterministic base name]</span><span>
</span><span id="line-159"></span><span>           </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933130"><span class="annot"><span class="annottext">libname :: String
</span><a href="#local-6989586621680933130"><span class="hs-identifier hs-var hs-var">libname</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933133"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933132"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-160"></span><span>               </span><span id="local-6989586621680933129"><span class="annot"><span class="annottext">filename :: String
</span><a href="#local-6989586621680933129"><span class="hs-identifier hs-var hs-var">filename</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933134"><span class="hs-identifier hs-var">dir</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="../../filepath/src/System.FilePath.Windows.html#%3C%2F%3E"><span class="hs-operator hs-var">&lt;/&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;lib&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933130"><span class="hs-identifier hs-var">libname</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="../../filepath/src/System.FilePath.Windows.html#%3C.%3E"><span class="hs-operator hs-var">&lt;.&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933137"><span class="hs-identifier hs-var">extn</span></a></span><span>
</span><span id="line-161"></span><span>           </span><span id="local-6989586621680933128"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680933128"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO Bool
</span><a href="../../directory/src/System.Directory.html#doesFileExist"><span class="hs-identifier hs-var">doesFileExist</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933129"><span class="hs-identifier hs-var">filename</span></a></span><span>
</span><span id="line-162"></span><span>           </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680933128"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; IO (String, String, String)
</span><a href="#local-6989586621680933135"><span class="hs-identifier hs-var">findTempName</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933134"><span class="hs-identifier hs-var">dir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933133"><span class="hs-identifier hs-var">prefix</span></a></span><span>
</span><span id="line-163"></span><span>                </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-comment">-- clean it up later</span><span>
</span><span id="line-164"></span><span>                        </span><span class="annot"><span class="annottext">DynFlags -&gt; TempFileLifetime -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#addFilesToClean"><span class="hs-identifier hs-var">addFilesToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933139"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">TempFileLifetime
</span><a href="#local-6989586621680933138"><span class="hs-identifier hs-var">lifetime</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933129"><span class="hs-identifier hs-var">filename</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-165"></span><span>                        </span><span class="annot"><span class="annottext">(String, String, String) -&gt; IO (String, String, String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933129"><span class="hs-identifier hs-var">filename</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933134"><span class="hs-identifier hs-var">dir</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933130"><span class="hs-identifier hs-var">libname</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-166"></span><span>
</span><span id="line-167"></span><span>
</span><span id="line-168"></span><span class="hs-comment">-- Return our temporary directory within tmp_dir, creating one if we</span><span>
</span><span id="line-169"></span><span class="hs-comment">-- don't have one yet.</span><span>
</span><span id="line-170"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#getTempDir"><span class="hs-identifier hs-type">getTempDir</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-171"></span><span id="getTempDir"><span class="annot"><span class="annottext">getTempDir :: DynFlags -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#getTempDir"><span class="hs-identifier hs-var hs-var">getTempDir</span></a></span></span><span> </span><span id="local-6989586621680933127"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933127"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-172"></span><span>    </span><span id="local-6989586621680933126"><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933126"><span class="hs-identifier hs-var">mapping</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Map String String) -&gt; IO (Map String String)
forall a. IORef a -&gt; IO a
</span><a href="../../base/src/GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Map String String)
</span><a href="#local-6989586621680933125"><span class="hs-identifier hs-var">dir_ref</span></a></span><span>
</span><span id="line-173"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">String -&gt; Map String String -&gt; Maybe String
forall k a. Ord k =&gt; k -&gt; Map k a -&gt; Maybe a
</span><a href="../../containers/src/Data.Map.Internal.html#lookup"><span class="hs-identifier hs-var">Map.lookup</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933123"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933126"><span class="hs-identifier hs-var">mapping</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-174"></span><span>        </span><span class="annot"><span class="annottext">Maybe String
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-175"></span><span>            </span><span id="local-6989586621680933122"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933122"><span class="hs-identifier hs-var">pid</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Int
</span><a href="GHC.SysTools.FileCleanup.html#getProcessID"><span class="hs-identifier hs-var">getProcessID</span></a></span><span>
</span><span id="line-176"></span><span>            </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933119"><span class="annot"><span class="annottext">prefix :: String
</span><a href="#local-6989586621680933119"><span class="hs-identifier hs-var hs-var">prefix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933123"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="../../filepath/src/System.FilePath.Windows.html#%3C%2F%3E"><span class="hs-operator hs-var">&lt;/&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ghc&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933122"><span class="hs-identifier hs-var">pid</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;_&quot;</span></span><span>
</span><span id="line-177"></span><span>            </span><span class="annot"><span class="annottext">IO String -&gt; IO String
forall a. IO a -&gt; IO a
</span><a href="../../base/src/GHC.IO.html#mask_"><span class="hs-identifier hs-var">mask_</span></a></span><span> </span><span class="annot"><span class="annottext">(IO String -&gt; IO String) -&gt; IO String -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
</span><a href="#local-6989586621680933118"><span class="hs-identifier hs-var">mkTempDir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933119"><span class="hs-identifier hs-var">prefix</span></a></span><span>
</span><span id="line-178"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680933117"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933117"><span class="hs-identifier hs-var">dir</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933117"><span class="hs-identifier hs-var">dir</span></a></span><span>
</span><span id="line-179"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-180"></span><span>    </span><span id="local-6989586621680933123"><span class="annot"><span class="annottext">tmp_dir :: String
</span><a href="#local-6989586621680933123"><span class="hs-identifier hs-var hs-var">tmp_dir</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; String
</span><a href="GHC.Driver.Session.html#tmpDir"><span class="hs-identifier hs-var">tmpDir</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933127"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-181"></span><span>    </span><span id="local-6989586621680933125"><span class="annot"><span class="annottext">dir_ref :: IORef (Map String String)
</span><a href="#local-6989586621680933125"><span class="hs-identifier hs-var hs-var">dir_ref</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IORef (Map String String)
</span><a href="GHC.Driver.Session.html#dirsToClean"><span class="hs-identifier hs-var hs-var">dirsToClean</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933127"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-182"></span><span>
</span><span id="line-183"></span><span>    </span><span class="annot"><a href="#local-6989586621680933118"><span class="hs-identifier hs-type">mkTempDir</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-184"></span><span>    </span><span id="local-6989586621680933118"><span class="annot"><span class="annottext">mkTempDir :: String -&gt; IO String
</span><a href="#local-6989586621680933118"><span class="hs-identifier hs-var hs-var">mkTempDir</span></a></span></span><span> </span><span id="local-6989586621680933115"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933115"><span class="hs-identifier hs-var">prefix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-185"></span><span>        </span><span id="local-6989586621680933114"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933114"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; IO Int
</span><a href="GHC.SysTools.FileCleanup.html#newTempSuffix"><span class="hs-identifier hs-var">newTempSuffix</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933127"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-186"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933112"><span class="annot"><span class="annottext">our_dir :: String
</span><a href="#local-6989586621680933112"><span class="hs-identifier hs-var hs-var">our_dir</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933115"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933114"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-187"></span><span>
</span><span id="line-188"></span><span>        </span><span class="hs-comment">-- 1. Speculatively create our new directory.</span><span>
</span><span id="line-189"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="../../directory/src/System.Directory.html#createDirectory"><span class="hs-identifier hs-var">createDirectory</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933112"><span class="hs-identifier hs-var">our_dir</span></a></span><span>
</span><span id="line-190"></span><span>
</span><span id="line-191"></span><span>        </span><span class="hs-comment">-- 2. Update the dirsToClean mapping unless an entry already exists</span><span>
</span><span id="line-192"></span><span>        </span><span class="hs-comment">-- (i.e. unless another thread beat us to it).</span><span>
</span><span id="line-193"></span><span>        </span><span id="local-6989586621680933111"><span class="annot"><span class="annottext">Maybe String
</span><a href="#local-6989586621680933111"><span class="hs-identifier hs-var">their_dir</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Map String String)
-&gt; (Map String String -&gt; (Map String String, Maybe String))
-&gt; IO (Maybe String)
forall a b. IORef a -&gt; (a -&gt; (a, b)) -&gt; IO b
</span><a href="../../base/src/GHC.IORef.html#atomicModifyIORef%27"><span class="hs-identifier hs-var">atomicModifyIORef'</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Map String String)
</span><a href="#local-6989586621680933125"><span class="hs-identifier hs-var">dir_ref</span></a></span><span> </span><span class="annot"><span class="annottext">((Map String String -&gt; (Map String String, Maybe String))
 -&gt; IO (Maybe String))
-&gt; (Map String String -&gt; (Map String String, Maybe String))
-&gt; IO (Maybe String)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680933110"><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933110"><span class="hs-identifier hs-var">mapping</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-194"></span><span>            </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">String -&gt; Map String String -&gt; Maybe String
forall k a. Ord k =&gt; k -&gt; Map k a -&gt; Maybe a
</span><a href="../../containers/src/Data.Map.Internal.html#lookup"><span class="hs-identifier hs-var">Map.lookup</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933123"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933110"><span class="hs-identifier hs-var">mapping</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-195"></span><span>                </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680933109"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933109"><span class="hs-identifier hs-var">dir</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933110"><span class="hs-identifier hs-var">mapping</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; Maybe String
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933109"><span class="hs-identifier hs-var">dir</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-196"></span><span>                </span><span class="annot"><span class="annottext">Maybe String
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; String -&gt; Map String String -&gt; Map String String
forall k a. Ord k =&gt; k -&gt; a -&gt; Map k a -&gt; Map k a
</span><a href="../../containers/src/Data.Map.Internal.html#insert"><span class="hs-identifier hs-var">Map.insert</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933123"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933112"><span class="hs-identifier hs-var">our_dir</span></a></span><span> </span><span class="annot"><span class="annottext">Map String String
</span><a href="#local-6989586621680933110"><span class="hs-identifier hs-var">mapping</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-197"></span><span>
</span><span id="line-198"></span><span>        </span><span class="hs-comment">-- 3. If there was an existing entry, return it and delete the</span><span>
</span><span id="line-199"></span><span>        </span><span class="hs-comment">-- directory we created.  Otherwise return the directory we created.</span><span>
</span><span id="line-200"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe String
</span><a href="#local-6989586621680933111"><span class="hs-identifier hs-var">their_dir</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-201"></span><span>            </span><span class="annot"><span class="annottext">Maybe String
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-202"></span><span>                </span><span class="annot"><span class="annottext">DynFlags -&gt; Int -&gt; MsgDoc -&gt; IO ()
</span><a href="GHC.Utils.Error.html#debugTraceMsg"><span class="hs-identifier hs-var">debugTraceMsg</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933127"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">(MsgDoc -&gt; IO ()) -&gt; MsgDoc -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-203"></span><span>                    </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Created temporary directory:&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933112"><span class="hs-identifier hs-var">our_dir</span></a></span><span>
</span><span id="line-204"></span><span>                </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933112"><span class="hs-identifier hs-var">our_dir</span></a></span><span>
</span><span id="line-205"></span><span>            </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680933104"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933104"><span class="hs-identifier hs-var">dir</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-206"></span><span>                </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="../../directory/src/System.Directory.html#removeDirectory"><span class="hs-identifier hs-var">removeDirectory</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933112"><span class="hs-identifier hs-var">our_dir</span></a></span><span>
</span><span id="line-207"></span><span>                </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933104"><span class="hs-identifier hs-var">dir</span></a></span><span>
</span><span id="line-208"></span><span>      </span><span class="annot"><span class="annottext">IO String -&gt; (IOException -&gt; IO String) -&gt; IO String
forall a. IO a -&gt; (IOException -&gt; IO a) -&gt; IO a
</span><a href="GHC.Utils.Exception.html#catchIO"><span class="hs-operator hs-var">`catchIO`</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680933101"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933101"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; Bool
</span><a href="../../base/src/System.IO.Error.html#isAlreadyExistsError"><span class="hs-identifier hs-var">isAlreadyExistsError</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933101"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-209"></span><span>                      </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
</span><a href="#local-6989586621680933118"><span class="hs-identifier hs-var">mkTempDir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933115"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO String
forall a. IOException -&gt; IO a
</span><a href="../../base/src/GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933101"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-210"></span><span>
</span><span id="line-211"></span><span class="hs-comment">{- Note [Deterministic base name]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The filename of temporary files, especially the basename of C files, can end
up in the output in some form, e.g. as part of linker debug information. In the
interest of bit-wise exactly reproducible compilation (#4012), the basename of
the temporary file no longer contains random information (it used to contain
the process id).

This is ok, as the temporary directory used contains the pid (see getTempDir).
-}</span><span>
</span><span id="line-222"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#removeTmpDirs"><span class="hs-identifier hs-type">removeTmpDirs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-223"></span><span id="removeTmpDirs"><span class="annot"><span class="annottext">removeTmpDirs :: DynFlags -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeTmpDirs"><span class="hs-identifier hs-var hs-var">removeTmpDirs</span></a></span></span><span> </span><span id="local-6989586621680933098"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933098"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680933097"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933097"><span class="hs-identifier hs-var">ds</span></a></span></span><span>
</span><span id="line-224"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; String -&gt; String -&gt; IO () -&gt; IO ()
forall a. DynFlags -&gt; String -&gt; String -&gt; IO a -&gt; IO a
</span><a href="GHC.Utils.Error.html#traceCmd"><span class="hs-identifier hs-var">traceCmd</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933098"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Deleting temp dirs&quot;</span></span><span>
</span><span id="line-225"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Deleting: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[String] -&gt; String
</span><a href="../../base/src/Data.OldList.html#unwords"><span class="hs-identifier hs-var">unwords</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933097"><span class="hs-identifier hs-var">ds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-226"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; [String] -&gt; IO ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m ()
</span><a href="../../base/src/Data.Foldable.html#mapM_"><span class="hs-identifier hs-var">mapM_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; (String -&gt; IO ()) -&gt; String -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeWith"><span class="hs-identifier hs-var">removeWith</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933098"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="../../directory/src/System.Directory.html#removeDirectory"><span class="hs-identifier hs-var">removeDirectory</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933097"><span class="hs-identifier hs-var">ds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-227"></span><span>
</span><span id="line-228"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#removeTmpFiles"><span class="hs-identifier hs-type">removeTmpFiles</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-229"></span><span id="removeTmpFiles"><span class="annot"><span class="annottext">removeTmpFiles :: DynFlags -&gt; [String] -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeTmpFiles"><span class="hs-identifier hs-var hs-var">removeTmpFiles</span></a></span></span><span> </span><span id="local-6989586621680933092"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933092"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680933091"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933091"><span class="hs-identifier hs-var">fs</span></a></span></span><span>
</span><span id="line-230"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ()
forall a. IO a -&gt; IO a
</span><a href="#local-6989586621680933090"><span class="hs-identifier hs-var">warnNon</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-231"></span><span>    </span><span class="annot"><span class="annottext">DynFlags -&gt; String -&gt; String -&gt; IO () -&gt; IO ()
forall a. DynFlags -&gt; String -&gt; String -&gt; IO a -&gt; IO a
</span><a href="GHC.Utils.Error.html#traceCmd"><span class="hs-identifier hs-var">traceCmd</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933092"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Deleting temp files&quot;</span></span><span>
</span><span id="line-232"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Deleting: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[String] -&gt; String
</span><a href="../../base/src/Data.OldList.html#unwords"><span class="hs-identifier hs-var">unwords</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933089"><span class="hs-identifier hs-var">deletees</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-233"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; [String] -&gt; IO ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m ()
</span><a href="../../base/src/Data.Foldable.html#mapM_"><span class="hs-identifier hs-var">mapM_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; (String -&gt; IO ()) -&gt; String -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeWith"><span class="hs-identifier hs-var">removeWith</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933092"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="../../directory/src/System.Directory.html#removeFile"><span class="hs-identifier hs-var">removeFile</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933089"><span class="hs-identifier hs-var">deletees</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-234"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-235"></span><span>     </span><span class="hs-comment">-- Flat out refuse to delete files that are likely to be source input</span><span>
</span><span id="line-236"></span><span>     </span><span class="hs-comment">-- files (is there a worse bug than having a compiler delete your source</span><span>
</span><span id="line-237"></span><span>     </span><span class="hs-comment">-- files?)</span><span>
</span><span id="line-238"></span><span>     </span><span class="hs-comment">--</span><span>
</span><span id="line-239"></span><span>     </span><span class="hs-comment">-- Deleting source files is a sign of a bug elsewhere, so prominently flag</span><span>
</span><span id="line-240"></span><span>     </span><span class="hs-comment">-- the condition.</span><span>
</span><span id="line-241"></span><span>    </span><span id="local-6989586621680933090"><span class="annot"><span class="annottext">warnNon :: IO b -&gt; IO b
</span><a href="#local-6989586621680933090"><span class="hs-identifier hs-var hs-var">warnNon</span></a></span></span><span> </span><span id="local-6989586621680933085"><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621680933085"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-242"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[String] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933083"><span class="hs-identifier hs-var">non_deletees</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621680933085"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-243"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-244"></span><span>        </span><span class="annot"><span class="annottext">DynFlags -&gt; MsgDoc -&gt; IO ()
</span><a href="GHC.Utils.Error.html#putMsg"><span class="hs-identifier hs-var">putMsg</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933092"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;WARNING - NOT deleting source files:&quot;</span></span><span>
</span><span id="line-245"></span><span>                       </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[MsgDoc] -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#hsep"><span class="hs-identifier hs-var">hsep</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(String -&gt; MsgDoc) -&gt; [String] -&gt; [MsgDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933083"><span class="hs-identifier hs-var">non_deletees</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-246"></span><span>        </span><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621680933085"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-247"></span><span>
</span><span id="line-248"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680933083"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933083"><span class="hs-identifier hs-var">non_deletees</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680933089"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933089"><span class="hs-identifier hs-var">deletees</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(String -&gt; Bool) -&gt; [String] -&gt; ([String], [String])
forall a. (a -&gt; Bool) -&gt; [a] -&gt; ([a], [a])
</span><a href="../../base/src/Data.OldList.html#partition"><span class="hs-identifier hs-var">partition</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
</span><a href="GHC.Driver.Phases.html#isHaskellUserSrcFilename"><span class="hs-identifier hs-var">isHaskellUserSrcFilename</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621680933091"><span class="hs-identifier hs-var">fs</span></a></span><span>
</span><span id="line-249"></span><span>
</span><span id="line-250"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#removeWith"><span class="hs-identifier hs-type">removeWith</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-251"></span><span id="removeWith"><span class="annot"><span class="annottext">removeWith :: DynFlags -&gt; (String -&gt; IO ()) -&gt; String -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#removeWith"><span class="hs-identifier hs-var hs-var">removeWith</span></a></span></span><span> </span><span id="local-6989586621680933078"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933078"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680933077"><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="#local-6989586621680933077"><span class="hs-identifier hs-var">remover</span></a></span></span><span> </span><span id="local-6989586621680933076"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933076"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="#local-6989586621680933077"><span class="hs-identifier hs-var">remover</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933076"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; (IOException -&gt; IO ()) -&gt; IO ()
forall a. IO a -&gt; (IOException -&gt; IO a) -&gt; IO a
</span><a href="GHC.Utils.Exception.html#catchIO"><span class="hs-operator hs-var">`catchIO`</span></a></span><span>
</span><span id="line-252"></span><span>  </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621680933075"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933075"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-253"></span><span>   </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933072"><span class="annot"><span class="annottext">msg :: MsgDoc
</span><a href="#local-6989586621680933072"><span class="hs-identifier hs-var hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; Bool
</span><a href="../../base/src/System.IO.Error.html#isDoesNotExistError"><span class="hs-identifier hs-var">isDoesNotExistError</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933075"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-254"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Warning: deleting non-existent&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933076"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-255"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Warning: exception raised when deleting&quot;</span></span><span>
</span><span id="line-256"></span><span>                                            </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933076"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">MsgDoc
</span><a href="GHC.Utils.Outputable.html#colon"><span class="hs-identifier hs-var">colon</span></a></span><span>
</span><span id="line-257"></span><span>               </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOException -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933075"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-258"></span><span>   </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Int -&gt; MsgDoc -&gt; IO ()
</span><a href="GHC.Utils.Error.html#debugTraceMsg"><span class="hs-identifier hs-var">debugTraceMsg</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680933078"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc
</span><a href="#local-6989586621680933072"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-259"></span><span>  </span><span class="hs-special">)</span><span class="hs-cpp">

#if defined(mingw32_HOST_OS)
</span><span class="hs-comment">-- relies on Int == Int32 on Windows</span><span>
</span><span id="line-263"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;_getpid&quot;</span></span><span> </span><span id="getProcessID"><span class="annot"><a href="GHC.SysTools.FileCleanup.html#getProcessID"><span class="hs-identifier hs-var">getProcessID</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-cpp">
#else
</span><span class="hs-identifier">getProcessID</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Int</span><span>
</span><span id="line-266"></span><span class="hs-identifier">getProcessID</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">System.Posix.Internals.c_getpid</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">fromIntegral</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-269"></span><span class="hs-comment">-- The following three functions are from the `temporary` package.</span><span>
</span><span id="line-270"></span><span>
</span><span id="line-271"></span><span class="hs-comment">-- | Create and use a temporary directory in the system standard temporary</span><span>
</span><span id="line-272"></span><span class="hs-comment">-- directory.</span><span>
</span><span id="line-273"></span><span class="hs-comment">--</span><span>
</span><span id="line-274"></span><span class="hs-comment">-- Behaves exactly the same as 'withTempDirectory', except that the parent</span><span>
</span><span id="line-275"></span><span class="hs-comment">-- temporary directory will be that returned by 'getTemporaryDirectory'.</span><span>
</span><span id="line-276"></span><span id="local-6989586621680933320"><span class="annot"><a href="GHC.SysTools.FileCleanup.html#withSystemTempDirectory"><span class="hs-identifier hs-type">withSystemTempDirectory</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>   </span><span class="hs-comment">-- ^ Directory name template. See 'openTempFile'.</span><span>
</span><span id="line-277"></span><span>                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680933320"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- ^ Callback that can use the directory</span><span>
</span><span id="line-278"></span><span>                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680933320"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-279"></span><span id="withSystemTempDirectory"><span class="annot"><span class="annottext">withSystemTempDirectory :: forall a. String -&gt; (String -&gt; IO a) -&gt; IO a
</span><a href="GHC.SysTools.FileCleanup.html#withSystemTempDirectory"><span class="hs-identifier hs-var hs-var">withSystemTempDirectory</span></a></span></span><span> </span><span id="local-6989586621680933066"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933066"><span class="hs-identifier hs-var">template</span></a></span></span><span> </span><span id="local-6989586621680933065"><span class="annot"><span class="annottext">String -&gt; IO a
</span><a href="#local-6989586621680933065"><span class="hs-identifier hs-var">action</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-280"></span><span>  </span><span class="annot"><span class="annottext">IO String
</span><a href="../../directory/src/System.Directory.html#getTemporaryDirectory"><span class="hs-identifier hs-var">getTemporaryDirectory</span></a></span><span> </span><span class="annot"><span class="annottext">IO String -&gt; (String -&gt; IO a) -&gt; IO a
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680933063"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933063"><span class="hs-identifier hs-var">tmpDir</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; (String -&gt; IO a) -&gt; IO a
forall a. String -&gt; String -&gt; (String -&gt; IO a) -&gt; IO a
</span><a href="GHC.SysTools.FileCleanup.html#withTempDirectory"><span class="hs-identifier hs-var">withTempDirectory</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933063"><span class="hs-identifier hs-var">tmpDir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933066"><span class="hs-identifier hs-var">template</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO a
</span><a href="#local-6989586621680933065"><span class="hs-identifier hs-var">action</span></a></span><span>
</span><span id="line-281"></span><span>
</span><span id="line-282"></span><span>
</span><span id="line-283"></span><span class="hs-comment">-- | Create and use a temporary directory.</span><span>
</span><span id="line-284"></span><span class="hs-comment">--</span><span>
</span><span id="line-285"></span><span class="hs-comment">-- Creates a new temporary directory inside the given directory, making use</span><span>
</span><span id="line-286"></span><span class="hs-comment">-- of the template. The temp directory is deleted after use. For example:</span><span>
</span><span id="line-287"></span><span class="hs-comment">--</span><span>
</span><span id="line-288"></span><span class="hs-comment">-- &gt; withTempDirectory &quot;src&quot; &quot;sdist.&quot; $ \tmpDir -&gt; do ...</span><span>
</span><span id="line-289"></span><span class="hs-comment">--</span><span>
</span><span id="line-290"></span><span class="hs-comment">-- The @tmpDir@ will be a new subdirectory of the given directory, e.g.</span><span>
</span><span id="line-291"></span><span class="hs-comment">-- @src/sdist.342@.</span><span>
</span><span id="line-292"></span><span id="local-6989586621680933316"><span class="annot"><a href="GHC.SysTools.FileCleanup.html#withTempDirectory"><span class="hs-identifier hs-type">withTempDirectory</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-comment">-- ^ Temp directory to create the directory in</span><span>
</span><span id="line-293"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>   </span><span class="hs-comment">-- ^ Directory name template. See 'openTempFile'.</span><span>
</span><span id="line-294"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680933316"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- ^ Callback that can use the directory</span><span>
</span><span id="line-295"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680933316"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-296"></span><span id="withTempDirectory"><span class="annot"><span class="annottext">withTempDirectory :: forall a. String -&gt; String -&gt; (String -&gt; IO a) -&gt; IO a
</span><a href="GHC.SysTools.FileCleanup.html#withTempDirectory"><span class="hs-identifier hs-var hs-var">withTempDirectory</span></a></span></span><span> </span><span id="local-6989586621680933062"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933062"><span class="hs-identifier hs-var">targetDir</span></a></span></span><span> </span><span id="local-6989586621680933061"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933061"><span class="hs-identifier hs-var">template</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-297"></span><span>  </span><span class="annot"><span class="annottext">IO String -&gt; (String -&gt; IO ()) -&gt; (String -&gt; IO a) -&gt; IO a
forall a b c. IO a -&gt; (a -&gt; IO b) -&gt; (a -&gt; IO c) -&gt; IO c
</span><a href="../../base/src/Control.Exception.Base.html#bracket"><span class="hs-identifier hs-var">Exception.bracket</span></a></span><span>
</span><span id="line-298"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; String -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#createTempDirectory"><span class="hs-identifier hs-var">createTempDirectory</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933062"><span class="hs-identifier hs-var">targetDir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933061"><span class="hs-identifier hs-var">template</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-299"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO () -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#ignoringIOErrors"><span class="hs-identifier hs-var">ignoringIOErrors</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; (String -&gt; IO ()) -&gt; String -&gt; IO ()
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="../../directory/src/System.Directory.html#removeDirectoryRecursive"><span class="hs-identifier hs-var">removeDirectoryRecursive</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-300"></span><span>
</span><span id="line-301"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#ignoringIOErrors"><span class="hs-identifier hs-type">ignoringIOErrors</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-302"></span><span id="ignoringIOErrors"><span class="annot"><span class="annottext">ignoringIOErrors :: IO () -&gt; IO ()
</span><a href="GHC.SysTools.FileCleanup.html#ignoringIOErrors"><span class="hs-identifier hs-var hs-var">ignoringIOErrors</span></a></span></span><span> </span><span id="local-6989586621680933055"><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621680933055"><span class="hs-identifier hs-var">ioe</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621680933055"><span class="hs-identifier hs-var">ioe</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; (IOException -&gt; IO ()) -&gt; IO ()
forall a. IO a -&gt; (IOException -&gt; IO a) -&gt; IO a
</span><a href="GHC.Utils.Exception.html#catchIO"><span class="hs-operator hs-var">`catchIO`</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IOException -&gt; IO ()
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-303"></span><span>
</span><span id="line-304"></span><span>
</span><span id="line-305"></span><span class="annot"><a href="GHC.SysTools.FileCleanup.html#createTempDirectory"><span class="hs-identifier hs-type">createTempDirectory</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-306"></span><span id="createTempDirectory"><span class="annot"><span class="annottext">createTempDirectory :: String -&gt; String -&gt; IO String
</span><a href="GHC.SysTools.FileCleanup.html#createTempDirectory"><span class="hs-identifier hs-var hs-var">createTempDirectory</span></a></span></span><span> </span><span id="local-6989586621680933053"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933053"><span class="hs-identifier hs-var">dir</span></a></span></span><span> </span><span id="local-6989586621680933052"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933052"><span class="hs-identifier hs-var">template</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-307"></span><span>  </span><span id="local-6989586621680933051"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933051"><span class="hs-identifier hs-var">pid</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Int
</span><a href="GHC.SysTools.FileCleanup.html#getProcessID"><span class="hs-identifier hs-var">getProcessID</span></a></span><span>
</span><span id="line-308"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; IO String
forall {t}. (Num t, Show t) =&gt; t -&gt; IO String
</span><a href="#local-6989586621680933050"><span class="hs-identifier hs-var">findTempName</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621680933051"><span class="hs-identifier hs-var">pid</span></a></span><span>
</span><span id="line-309"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621680933050"><span class="annot"><span class="annottext">findTempName :: t -&gt; IO String
</span><a href="#local-6989586621680933050"><span class="hs-identifier hs-var hs-var">findTempName</span></a></span></span><span> </span><span id="local-6989586621680933043"><span class="annot"><span class="annottext">t
</span><a href="#local-6989586621680933043"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-310"></span><span>            </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680933041"><span class="annot"><span class="annottext">path :: String
</span><a href="#local-6989586621680933041"><span class="hs-identifier hs-var hs-var">path</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933053"><span class="hs-identifier hs-var">dir</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="../../filepath/src/System.FilePath.Windows.html#%3C%2F%3E"><span class="hs-operator hs-var">&lt;/&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933052"><span class="hs-identifier hs-var">template</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">t -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">t
</span><a href="#local-6989586621680933043"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-311"></span><span>            </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="../../directory/src/System.Directory.html#createDirectory"><span class="hs-identifier hs-var">createDirectory</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933041"><span class="hs-identifier hs-var">path</span></a></span><span>
</span><span id="line-312"></span><span>            </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621680933041"><span class="hs-identifier hs-var">path</span></a></span><span>
</span><span id="line-313"></span><span>          </span><span class="annot"><span class="annottext">IO String -&gt; (IOException -&gt; IO String) -&gt; IO String
forall a. IO a -&gt; (IOException -&gt; IO a) -&gt; IO a
</span><a href="GHC.Utils.Exception.html#catchIO"><span class="hs-operator hs-var">`catchIO`</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621680933040"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933040"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; Bool
</span><a href="../../base/src/System.IO.Error.html#isAlreadyExistsError"><span class="hs-identifier hs-var">isAlreadyExistsError</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933040"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-314"></span><span>                          </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">t -&gt; IO String
</span><a href="#local-6989586621680933050"><span class="hs-identifier hs-var">findTempName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">t
</span><a href="#local-6989586621680933043"><span class="hs-identifier hs-var">x</span></a></span><span class="annot"><span class="annottext">t -&gt; t -&gt; t
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">t
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO String
forall a. IOException -&gt; IO a
</span><a href="../../base/src/GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621680933040"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-315"></span></pre></body></html>